﻿<?php
	class LoginAction extends Action{
		public function login(){
			$this->display();
		}
		public function dologin(){
			$username=$_POST['username'];
			$password=$_POST['password'];
			$code=$_POST['code'];

			if(md5($code)!=$_SESSION['code']){
				$this->error('验证码不正确'); 
			}
			$user=M('User');
			$where['username']=$username;
			$where['password']=$password;
			$count=$user->where($where)->find();
			$show=$user->select();
			if($count>0){
				$_SESSION['username']=$username;
				$_SESSION['id']=$count['id'];
				//($count['id']);
				$this->success('用户登录成功',U('Index/index'));
			}else{
				$this->error('用户名不存在');
			}
			
		}
		//退出
		public function dologout(){
			$_SESSION=array();
			if(isset($_COOKIE[session_name()])){
					setcookie(session_name(),'',time()-1,'/');
					//$this->redirect('Login/login');
			}
				session_destroy();//清除
				$this->redirect('Index/index');
			 
		}

	}
?>